<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>申请中介交易 - {$settings.site.sitename}</title>
    <meta name="keywords" content="{$settings.site.seo_keywords}" />
    <meta name="description" content="{$settings.site.seo_description}" />
	{include file="public/css"}

   {include file="public/js"}
<style>
.banner-title{font-size:38px;line-height:150px;text-align:center;}
</style>
</head>
<body class="layui-bg-gray">
{include file="public/header"}
<div class="layui-container">
<div class="layui-main trade-add">
<div class="layui-row layui-col-space10">

   <!-- 项目进度条 -->
   {include file="trade/order_step"}

    <div class="trade-add-left">

      	<fieldset class="layui-elem-field layui-field-title">
		  <legend>发起中介交易</legend>
		  <div class="layui-field-box">
		    
				<form class="layui-form" action="post" >
            <input type="hidden" name="id" value="{$Request.param.id}">
            <div class="layui-form-item">
            <label class="layui-form-label">交易分类</label>
                
            <div class="layui-input-inline" style="width:600px" > 
            
             
                {:get_cate('guarantee_category',$guaranteeInfo.cid)}
            </div>
          </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">交易标题</label>
				        <div class="layui-input-inline" style="width:150px" >

					    </div>

				    <div class="layui-input-inline" style="width:350px" > 
				      <input type="text" name="title" lay-verify="title" maxlength="25" autocomplete="off" placeholder="请输入中介交易标题，最多25个字" class="layui-input" value="{$guaranteeInfo.title}">
				    </div>
				  </div>

				  <div class="layui-form-item">
				    <label class="layui-form-label">我的身份</label>
				    <div class="layui-input-inline">
              {if !empty($guaranteeInfo)}
              {if $guaranteeInfo.id_type ==0 }
               <input type="hidden" name="id_type" value="1" > 
               <div class="layui-form-mid layui-word-aux"  > 卖家</div>
              {else}
               <input type="hidden" name="id_type" value="0" > 
                <div class="layui-form-mid layui-word-aux"  >买家</div>
              {/if}
              {else}
              <input type="radio" name="id_type" value="0" checked  title="买家">
              <input type="radio" name="id_type" value="1"   title="卖家" >
              {/if}


				    </div>
				  </div>

			  <div class="layui-form-item">
				    <label class="layui-form-label">对方用户名</label>
				    <div class="layui-input-inline">
				      <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="" class="layui-input" value="{$guaranteeInfo.username}">
				    </div>
				  </div>
					  <div class="layui-form-item">
				    <label class="layui-form-label">交易价格</label>
				    <div class="layui-input-inline">
				      <input type="text" name="price" id="price" maxlength="13"  lay-verify="price" autocomplete="off" placeholder="交易价格最少1元" class="layui-input" value="{$guaranteeInfo.price}">
				    </div>
				  </div>	 
            <div class="layui-form-item">
            <label class="layui-form-label">手续费</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid layui-word-aux">{if !empty($settings.guarantee.fee_ratio)}{$settings.guarantee.fee_ratio} %{else}免费手续费{/if}</div>
            </div>
          </div>

				  <div class="layui-form-item">
				    <label class="layui-form-label">中介费</label>
				    <div class="layui-input-inline" style="width:450px;">
				          <input type="radio" name="fee_type" lay-filter="fee_type" value="1" title="买家全付" checked>
                   <input type="radio" name="fee_type" lay-filter="fee_type" value="2"  title="卖家全付">
                   <input type="radio" name="fee_type" lay-filter="fee_type" value="3" title="双方各付一半" >
				    </div>
				  </div>

			      <div class="layui-form-item">
				    <label class="layui-form-label">实际结算</label>
				    <div class="layui-input-inline">
				          <input type="hidden"  name="buyer_pay" id="buyer_pay" value="">
                          <input type="hidden"  name="seller_get" id="seller_get" value="">
                      
				    </div>
				       <div class="layui-input-block" id="result" style="padding:8px">
                   
                        </div> 
				  </div>



			      <div class="layui-form-item">
				    <label class="layui-form-label">交易内容</label>
				    <div class="layui-input-block">
				     {form:ueditor name="content" value="htmlspecialchars_decode($guaranteeInfo['content'])" /}
				    </div>
				  </div>
			      <div class="layui-form-item">
				    
				    <div class="layui-input-block" style="text-align:right">
				        <button class="layui-btn layui-btn-normal" style="width:100px;" lay-submit="" lay-filter="form" data-url="{:url('trade/create')}">发起交易</button>
				    </div>
				  </div>

				</form>

		  </div>
		</fieldset>
    </div>
  <div class="trade-add-right">
      <div class="layui-card">
		    <div class="layui-card-header">中介客服</div>
		    <div class="layui-card-body">
		      客服电话：{$settings.site.telphone}<br>
		     客服QQ：{$settings.site.qq}
		    </div>
		 </div>
    <div class="layui-card">
  		  <div class="layui-card-header">手续费</div>
  		  <div class="layui-card-body">
  		     中介担保平台仅收取{$settings.guarantee.fee_ratio}% 手续费
  		  </div>
  	</div>
</div>

</div>

</div>
</div>

{include file="public/footer"}
<script>
layui.use(['layer','form','layedit'], function(){
  var form = layui.form;
  var layer = layui.layer;
  var layedit = layui.layedit
  
  //监听提交
  form.on('submit(form)', function(data){
  var url = $(this).attr('data-url');
  if(url ==''){
    layer.msg('请求的url不存在');
  }
    $.post(url,data.field,function(json){
      if(json.code == '0'){
        location.href= json.data.url;
      }else{
      	qilecms.error(json.msg);
      }
    });
   

    return false;

  });


  money();
// 计算费用 
 $('#price').on('keyup',function(){
     money();
 });

 form.on("radio(fee_type)",function(){
    money();
 });
 // 计算费用 函数
function money()
{
      var fee_type = $("input[name='fee_type']:checked").val();
      if(fee_type < 0){
        layer.msg('请选择中介费支付方式');
        return false;
      }
       var price = $("#price").val(); //价格
       var fee_ratio = "{$settings.guarantee.fee_ratio}"; //手续费比例
      if(fee_ratio =='' || fee_ratio <= 0){
        fee_ratio = 0;
      }
      price = parseInt(price);
      fee_ratio =  parseInt(fee_ratio);
       if(price >=1 ){
          var fee =  price * (fee_ratio/100);
          if(fee_type ==1){
       
            var buyer = '买家支付 <span class="orange">'+ (price+fee)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ price+'</span> 元';
            $("#buyer_pay").val(price+fee);
            $("#seller_get").val(price);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==2){
            var buyer = '买家支付 <span class="orange">'+ (price)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-fee)+'</span> 元';
            $("#buyer_pay").val(price);
            $("#seller_get").val(price-fee);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==3){
            var buyer = '买家支付 <span class="orange">'+ (price+fee/2)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-fee/2)+'</span>元';
            $("#buyer_pay").val(price-fee/2);
            $("#seller_get").val(price-fee/2);
            $("#result").html(buyer+' '+seller);
          }
         
       }else{
          $("#result").html('<span class="orange">交易价格最少1元</span>');
       }
}



  //构建一个默认的编辑器
  var index = layedit.build('LAY_demo1');
  
  //编辑器外部操作
  var active = {
    content: function(){
      alert(layedit.getContent(index)); //获取编辑器内容
    }
    ,text: function(){
      alert(layedit.getText(index)); //获取编辑器纯文本内容
    }
    ,selection: function(){
      alert(layedit.getSelection(index));
    }
  };
  
  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  //自定义工具栏
  layedit.build('LAY_demo2', {
    tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
    ,height: 100
  }) 














});
</script>

</body>
</html>